x = [-1; 0; 0; 1; 1; -1];
y = [1; 1; 0; 0; -1; -1];

res = 10;
scale = 0.9;

[px1, py1] = meshgrid(0:res, 0:res);
[px2, py2] = meshgrid(0:res, 0:res);
[px3, py3] = meshgrid(0:res, 0:res);

px1 = reshape(px1, (res+1)*(res+1), 1) / res * scale - scale / 2;
px2 = reshape(px2, (res+1)*(res+1), 1) / res * scale - scale / 2;
px3 = reshape(px3, (res+1)*(res+1), 1) / res * scale - scale / 2;
py1 = reshape(py1, (res+1)*(res+1), 1) / res * scale - scale / 2;
py2 = reshape(py2, (res+1)*(res+1), 1) / res * scale - scale / 2;
py3 = reshape(py3, (res+1)*(res+1), 1) / res * scale - scale / 2;

px1 = px1 - 0.5;
py1 = py1 + 0.5;
px2 = px2 - 0.5;
py2 = py2 - 0.5;
px3 = px3 + 0.5;
py3 = py3 - 0.5;

px = [x; px1; px2; px3];
py = [y; py1; py2; py3];

dim = size(px, 1);

c = [1,2; 2,3; 3,4; 4,5; 5,6; 6,1];
dt = DelaunayTri(px,py,c);

io = dt.inOutStatus();
tri = dt(io, :);

% patch('faces', dt(io, :), 'vertices', dt.X, 'color', [1:6], 'FaceColor', 'interp')

% triplot(dt(io, :))

trisurf(tri, px, py, zeros(dim, 1), [1:dim], 'FaceColor', 'interp')

% axis([-1, 1; -1, 1])

colorbar

view(2)

% triplot(dt);